<?php
//MIPJZ.Com [Don't forget the beginner's mind]
//Copyright (c) 2017~2099 http://MIPJZ.Com All rights reserved.
namespace addons\spiderOneMore\controller;
use think\Request;
use think\Loader;
use think\Db;
use think\Controller;
class GlobalAction extends Controller
{
    public function spiderOneMore()
    {
        $userAgent = @Request::instance()->header()['user-agent'];
        
        if (strpos($userAgent,"YisouSpider") !== false) {
            $dateInfo = db('SpiderOneMore')->where('date',date("Y-m-d"))->find();
            if ($dateInfo) {
                db('SpiderOneMore')->where('date',date("Y-m-d"))->update(array(
                    'date' => date("Y-m-d"),
                    'sm' => $dateInfo['sm'] + 1,
                ));
            } else {
                db('SpiderOneMore')->insert(array(
                    'date' => date("Y-m-d"),
                    'sm' => $dateInfo['sm'] + 1,
                ));
            }
            db('SpiderOneSm')->insert(array('add_time' => time(),'type' => 'pc','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
        }
        
        if (strpos($userAgent,"Baiduspider") !== false) {
            $dateInfo = db('SpiderOneMore')->where('date',date("Y-m-d"))->find();
            if ($dateInfo) {
                db('SpiderOneMore')->where('date',date("Y-m-d"))->update(array(
                    'date' => date("Y-m-d"),
                    'baidu' => $dateInfo['baidu'] + 1,
                ));
            } else {
                db('SpiderOneMore')->insert(array(
                    'date' => date("Y-m-d"),
                    'baidu' => $dateInfo['baidu'] + 1,
                ));
            }
            if (strpos($userAgent,"Mobile") !== false) {
                if (strpos($userAgent,"render") !== false) {
                    db('SpiderOneBaidu')->insert(array('add_time' => time(),'type' => 'mobileRender','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
                } else {
                    db('SpiderOneBaidu')->insert(array('add_time' => time(),'type' => 'mobile','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
                }
            } else {
                if (strpos($userAgent,"render") !== false) {
                    db('SpiderOneBaidu')->insert(array('add_time' => time(),'type' => 'pcRender','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
                } else {
                    db('SpiderOneBaidu')->insert(array('add_time' => time(),'type' => 'pc','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
                }
            }
        }
        if (strpos($userAgent,"Sogou") !== false) {
            $dateInfo = db('SpiderOneMore')->where('date',date("Y-m-d"))->find();
            if ($dateInfo) {
                db('SpiderOneMore')->where('date',date("Y-m-d"))->update(array(
                    'date' => date("Y-m-d"),
                    'sogou' => $dateInfo['sogou'] + 1,
                ));
            } else {
                db('SpiderOneMore')->insert(array(
                    'date' => date("Y-m-d"),
                    'sogou' => $dateInfo['sogou'] + 1,
                ));
            }
            db('SpiderOneSogou')->insert(array('add_time' => time(),'type' => 'pc','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
        }
        
        if (strpos($userAgent,"Googlebot") !== false) {
            $dateInfo = db('SpiderOneMore')->where('date',date("Y-m-d"))->find();
            if ($dateInfo) {
                db('SpiderOneMore')->where('date',date("Y-m-d"))->update(array(
                    'date' => date("Y-m-d"),
                    'google' => $dateInfo['google'] + 1,
                ));
            } else {
                db('SpiderOneMore')->insert(array(
                    'date' => date("Y-m-d"),
                    'google' => $dateInfo['google'] + 1,
                ));
            }
            db('SpiderOneGoogle')->insert(array('add_time' => time(),'type' => 'pc','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
        }
        
        if (strpos($userAgent,"360") !== false) {
            $dateInfo = db('SpiderOneMore')->where('date',date("Y-m-d"))->find();
            if ($dateInfo) {
                db('SpiderOneMore')->where('date',date("Y-m-d"))->update(array(
                    'date' => date("Y-m-d"),
                    '360' => $dateInfo['360'] + 1,
                ));
            } else {
                db('SpiderOneMore')->insert(array(
                    'date' => date("Y-m-d"),
                    '360' => $dateInfo['360'] + 1,
                ));
            }
            db('spider_one_360')->insert(array('add_time' => time(),'type' => 'pc','pageUrl' => $this->view->siteUrl, 'ip' => Request::instance()->ip()));
        }
    }
 

}

